﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace m10cde_WinForms{
    ///<summary>
    /// Abstract class that the shape classes will inherit from, implements all functionality of a shape
    ///</summary>
    public abstract class Shape{
        public Block myBlock1;
        public Block myBlock2;
        public Block myBlock3;
        public Block myBlock4;
        public Block[,] shapeLayout = new Block[3,3];    // i'm thinking we could use a 4*4 array(0 to 3) to hold the blocks
        String colour; //might be redundant
        String shape;
        Char facingDirection = 'N'; //shape defaults to North when created
        bool isMoving = false;  //might be handy for collision detection later on
        
        ///<summary>
        /// Constructor, makes a shape with the necessary info
        ///</summary>
        public Shape(String colour, String shape, String direction, Block myBlock1, Block myBlock2, Block myBlock3, Block myBlock4){
            this.colour = colour;
            this.shape = shape;
            this.myBlock1 = myBlock1;
            this.myBlock2 = myBlock2;
            this.myBlock3 = myBlock3;
            this.myBlock4 = myBlock4;
            setIsMoving(true);
        }

        /// <summary>
        /// empty constructor
        /// </summary>
        public Shape(){
        }

        ///<summary>
        /// method to rotate shape 90* based on current direction
        ///</summary>
        public void rotate(int facingDirection){
            //if north then rotate to east
            if (facingDirection == 'N'){
                changeFacingDirection('E');
            }

            //if east then rotate to south
            if (facingDirection == 'E'){
                changeFacingDirection('S');
            }

            //if south then west
            if (facingDirection == 'S'){
                changeFacingDirection('W');
            }

            //if west then north
            if (facingDirection == 'W'){
                changeFacingDirection('N');
            }

            //maybe easier to just have it rotate clockwise, instead of clockwise + anti-clockwise
        }

        ///<summary>
        /// assign the blocks within the shape a colour
        ///</summary>
        public void setColour(){
            /// TODO add a way to set the blocks colour
        }

        ///<summary>
        /// method to handle the user moving the shape in different directions
        /// move the shape left/right/down
        /// if direction = 1, move left
        /// if direction = 2, move right
        /// if direction = 3, move down
        ///</summary>
        public void move(int direction){
            if (direction == 1)
                myBlock1.xPosition--;
                myBlock2.xPosition--;
                myBlock3.xPosition--;
                myBlock4.xPosition--;
            if (direction == 2)
                myBlock1.xPosition++;
                myBlock2.xPosition++;
                myBlock3.xPosition++;
                myBlock4.xPosition++;
            if (direction == 3)
                myBlock1.yPosition--;
                myBlock2.yPosition--;
                myBlock3.yPosition--;
                myBlock4.yPosition--;
        }

        ///<summary>
        /// a method to change the direction the shape faces
        ///</summary>
        public void changeFacingDirection(Char newDirection){
            facingDirection = newDirection;
        }

        /// <summary>
                /// a Method to check if the shape has stopped moving
        /// </summary>
        /// <returns>a boolean</returns>
        public Boolean isShapeMoving(){
            if (this.isMoving == true){
                return true;
            }
            else{
                return false;
            }
        }

        /// <summary>
        /// used to set the current status of the shape, if it is moving or not
        /// can be true or false
        /// </summary>
        /// <param name="status"></param>
        public void setIsMoving(Boolean status){
            this.isMoving = status;
        }

        ///<summary>
        /// method used to set the shape layout of the 4 blocks within the 4*4 grid
        /// this creates a line of blocks on the top row, will need to be overridden in sub-classes
        ///         /// Creates a line of blocks
        ///     0   1   2   3
        /// 0   *   *   *   *
        /// 1          
        /// 2          
        /// 3
        ///</summary>
        public virtual void createShapeLayout()
        {
            shapeLayout[0, 0] = myBlock1;
            shapeLayout[0, 1] = myBlock2;
            shapeLayout[0, 2] = myBlock3;
            shapeLayout[0, 3] = myBlock4;
            
        }

        ///<summary>
        /// output some shape info, debugging usage
        ///</summary>
        public String toString(String colour, String shape, String direction){
            // TODO complete this
            return colour + " "+ shape + " " + direction + "  " + isMoving;
        }
    }
}
